package com.gitee.wsl.func.procedure.sample

import com.gitee.wsl.func.procedure.Procedure
import com.gitee.wsl.func.Function

class GroupByUniqueKeyProcedure<T, K>(
    private val map: MutableMap<K, T>,
    private val keyFunction: Function<in T, out K>
) : Procedure<T> {
    override fun value(each: T) {
        val key = this.keyFunction(each)
        check(this.map.put(key, each) == null) { "Key $key already exists in map!" }
    }

}
